﻿using Caliburn.Micro;
using GalaSoft.MvvmLight.CommandWpf;
using MvvmValidationDemo.Interfaces;

namespace MvvmValidationDemo.ViewModels
{
    public class MainViewModel : Screen, IValidationExceptionHandler
    {
        private bool _isValid=true;
        private string _text1;
        private string _text2;

        public bool IsValid
        {
            get
            {
                return _isValid;
            }
            set
            {
                if (value == _isValid)
                    return;
                _isValid = value;
                NotifyOfPropertyChange(() => IsValid);
            }
        }

        public string Text1
        {
            get
            {
                return _text1;
            }
            set
            {
                if (value == _text1)
                    return;
                _text1 = value;
                NotifyOfPropertyChange(() => Text1);
            }
        }

        public string Text2
        {
            get
            {
                return _text2;
            }
            set
            {
                if (value == _text2)
                    return;
                _text2 = value;
                NotifyOfPropertyChange(() => Text2);
            }
        }

        public RelayCommand OkCommand
        {
            get;
            set;
        }

        public MainViewModel()
        {
            OkCommand = new RelayCommand(OkCommandHandler, CanOkCommandExecute);
        }

        private void OkCommandHandler()
        {

        }

        private bool CanOkCommandExecute()
        {
            return IsValid;
        }


    }
}